package com.etogc.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.etogc.groupchat.R;

public class CommonDialog extends Dialog {

    private String mIntro;
    private String mTitle;
    private Context mContext;

    private CommonDialog mInputCodeDialog;

    private onOkClickListener onOkClickListener;

    public CommonDialog(Context context, int theme) {
        super(context, theme);
    }

    public CommonDialog(Context context, String title, String intro) {
        super(context);
        this.mContext = context;
        this.mTitle = title;
        this.mIntro = intro;
    }

    public CommonDialog initDialog() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mInputCodeDialog = new CommonDialog(mContext, R.style.MyDialog);
        View layout = inflater.inflate(R.layout.dialog_common, null);
        mInputCodeDialog.addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        TextView title = layout.findViewById(R.id.tv_title);
        TextView intro = layout.findViewById(R.id.tv_intro);

        if (!TextUtils.isEmpty(mTitle)) {
            title.setText(mTitle);
        }
        if (!TextUtils.isEmpty(mIntro)) {
            intro.setText(mIntro);
        }

        layout.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mInputCodeDialog.dismiss();
            }
        });

        layout.findViewById(R.id.tv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onOkClickListener.onSure();
            }
        });
        mInputCodeDialog.setContentView(layout);
        return mInputCodeDialog;
    }

    public CommonDialog.onOkClickListener getOnOkClickListener() {
        return onOkClickListener;
    }

    public void setOnOkClickListener(CommonDialog.onOkClickListener onOkClickListener) {
        this.onOkClickListener = onOkClickListener;
    }

    public interface onOkClickListener {
        void onSure();
    }

}
